package com.example.ipccore;

import android.text.TextUtils;
import android.util.Log;

import com.google.gson.Gson;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class BPBinder implements InvocationHandler {
    private Class clazz;
    public <T> BPBinder(Class<T> clazz) {
        this.clazz=clazz;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //由BPBinder将要跨进程调用的函数及信息，转成序列化数据进行跨进程传输调用。
        Log.e("xunyou", "invoke: "+method.getName());
        String str = ServiceManager.getDefault().sendRequest(clazz, method, args, TuYaService.TYPE_INVOKE);
        if (!TextUtils.isEmpty(str)) {
            Object object = new Gson().fromJson(str, method.getReturnType());
            return object;
        }
        Log.e("xunyou", "invoke--str: "+str);
        return null;
    }
}
